using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace Decav.Gatsb.Application.CommandWorkflow
{
    /// <summary>
    /// Finds locations in the Gatsb database.
    /// </summary>
	public partial class GetLocationsActivity: Activity
	{
		public GetLocationsActivity()
		{
			InitializeComponent();
		}

        /// <summary>
        /// The dependency property that gets or sets the text to query location on.
        /// </summary>
        public static DependencyProperty QueryTextProperty = DependencyProperty.Register(
            "QueryText", typeof(string), typeof(GetLocationsActivity));

        /// <summary>
        /// Gets or sets the text to query location on.
        /// </summary>
        [ValidationOption(ValidationOption.Required)]
        public string QueryText
        {
            get { return (string)GetValue(QueryTextProperty); }
            set { SetValue(QueryTextProperty, value); }
        }        
        

        /// <summary>
        /// The dependency property that gets or sets the locations that were found.
        /// </summary>
        public static DependencyProperty LocationsProperty = DependencyProperty.Register(
            "Locations", typeof(Location[]), typeof(GetLocationsActivity));

        /// <summary>
        /// Gets or sets the locations that were found.
        /// </summary>
        public Location[] Locations
        {
            get { return (Location[])GetValue(LocationsProperty); }
            set { SetValue(LocationsProperty, value); }
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            Locations = GatsbApplication.Current.FindLocation(
                LocationSearchCriteria.Parse(QueryText));

            return ActivityExecutionStatus.Closed;
        }
        
	}
}
